home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume7 / yearlength < prev    next >
Encoding:
Internet Message Format  |  1987-01-19  |  30.1 KB

  1. Subject:  v07i099:  Compute length of any year
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: seismo!nbires!vianet!devine
  6. Mod.sources: Volume 7, Issue 99
  7. Archive-name: yearlength
  8.  
  9. Enclosed is a collection of files that deal with determining the actual
  10. length of a calendar year for the years 1 through 9999.  I realize that
  11. the program is severely lacking in a good main() but it was only there
  12. for the testing.
  13.     Bob Devine
  14.     (seismo!nbires!vianet!devine)
  15.  
  16. --------------------------------------
  17. #! /bin/sh
  18. # This is a shell archive, meaning:
  19. # 1.  Remove everything above the #! /bin/sh line.
  20. # 2.  Save the resulting test in a file
  21. # 3.  Execute the file with /bin/sh (not csh) to create the files:
  22. #
  23. #        READ_ME
  24. #        Makefile
  25. #        main.c
  26. #        days.c
  27. #        early.c
  28. #        year.tbl
  29. #
  30. # Created by devine (Bob Devine) on Tue Nov 11 20:16:26 MST 1986
  31. #
  32. if test -f 'READ_ME'
  33. then
  34.     echo shar: will not over-write existing file "'READ_ME'"
  35. else
  36. echo extracting "'READ_ME'"
  37. sed 's/^X//' >READ_ME <<'SHAR_EOF'
  38. X
  39. X
  40. X  This collection of functions attempts to provide the number of
  41. Xdays in a year based upon a selected year and country.  It is
  42. Xbeing posted because of a promise I made to the readers of net.lang.c.
  43. X
  44. X  There are basically three levels of that can be used in to calculate
  45. Xhow long a year is:
  46. X
  47. X    1. Divisibility by 4 -- this works for the years 1901-2099 and,
  48. X       as a result, is suitable for nearly all programs.  It can be
  49. X       coded as:                     or a faster version:
  50. X       
  51. X       if (year % 4 == 0)             if ((year & 0x03) == 0)
  52. X           days_in_year = 366;            days_in_year = 366;
  53. X       else                           else
  54. X           days_in_year = 365;            days_in_year = 365;
  55. X
  56. X
  57. X    2. Gregorian rules -- this works from the year after your country
  58. X       adopted the Gregorian calendar through the forseeable future.
  59. X       It can be coded as:
  60. X
  61. X       if (year%4 == 0 && year%100 != 0 || year%400 == 0)
  62. X           days_in_year = 366;
  63. X       else
  64. X           days_in_year = 365;
  65. X
  66. X       or slightly faster (as Karl Heuer suggested to me via mail):
  67. X
  68. X       if ((year%4 == 0) && (year%100 != 0 || year%400 == 0))
  69. X           days_in_year = 366;
  70. X       else
  71. X           days_in_year = 365;
  72. X
  73. X       or (depending on how the remainder operator is implemented)
  74. X       this is up to 5 times faster by taking advantage of some
  75. X       common factors of 100 and 400:
  76. X
  77. X       register int ndiv100;    /* Boolean for not divisible by 100 */
  78. X
  79. X       if ((year&0x3)==0 && (ndiv100=year%100) || (year&0xF)==0 && !ndiv100)
  80. X           days_in_year = 366;
  81. X       else
  82. X           days_in_year = 365;
  83. X
  84. X       or even faster by using Karl Heuer's suggestion of reordering
  85. X       the expression:
  86. X
  87. X       if ((year&0x3)==0 && ((year&0xF)==0 || year%100!=0))
  88. X           days_in_year = 366;
  89. X       else
  90. X           days_in_year = 365;
  91. X
  92. X       I believe that this is the fastest possible check for leap years.
  93. X       Does anyone know of a fast check for remainders so that the "% 100"
  94. X       test can be speeded up?
  95. X
  96. X    3. Country-dependent rules --  which is what this collection of
  97. X       functions attempt to do.  It gets messy.
  98. X
  99. X
  100. X
  101. XBACKGROUND INFORMATION OF COUNTRY-DEPENDENT RULES
  102. X-------------------------------------------------
  103. X
  104. X  When dealing with calendars based on different epochs (e.g., Egyptian,
  105. XRoman Republican, Julian, Augustan, Christian/Gregorian, Jewish, Muslim,
  106. XChinese, Mayan, Japanese) it is easier to convert dates into a scheme that
  107. Xhas a starting date older than that of any of the epochs.  Such a scheme
  108. Xwas invented by J. Scalinger in 1583.  
  109. X
  110. X  However, all years as used by this package are those of the Christian
  111. Xera because that is the most common representation used throughout the
  112. Xworld.  Valid years are 1AD through 9999AD.   There is no year 0.  Negative
  113. Xyears (those BC) are not used in this program because the Julian calendar
  114. Xwas still being changed by Augustus in 8BC (renamed the month Sextilus
  115. Xto August and changed the number of days in several months).
  116. X
  117. X  The argument may be made that going to years before the 4th Century AD
  118. Xis fruitless.  It is about that time that the Emperor Constantine (he had
  119. Xpreviously converted to Christianity) made the 7 day week official
  120. Xthroughout the Roman Empire.  The Celtic calendar had 8 days but the
  121. Xcalendar Moses took with him from Egypt had 7.  It's fascinating how
  122. Xcalendars tie in with history.  Had the Nazis won WW2, we now might have
  123. Xa calendar based on the birth of Hitler!  And it was about that time that
  124. Xthe year of Christ's birth, instead of the start of City of Rome, was
  125. Xsuggested as the basis for counting years.
  126. X
  127. X  It is not possible to guarentee the accuracy for very early dates.  
  128. XThe references that I consulted occasionally would disagree on dates.
  129. XThere are many difficulties in arriving at a definitive answer for
  130. Xa region's calendar because of national and supernational influences.
  131. XSome of these are: wars that change boundaries; country-dwellers
  132. Xresistance to the calendar change wrought by the city-based government;
  133. Xand religous differences over what is the "right" calendar.  Many
  134. XProtestants chose to be "wrong with the calendar rather than right with
  135. Xthe Pope".  For examples of such turmoil see any of the *_early() functions.
  136. X
  137. X  An assumption that I used to decide when a country should be put
  138. Xin the switched-to-Gregorian calendar list, if I could not find a
  139. Xclear date, was to take the switch over date of its ruling country.
  140. XAll of the South American countries use Spain's date even though
  141. Xthe reality of when countries actually changed is much more complex.
  142. XThe many British colonies use the same year as Great Britain, 1752.
  143. XSee canada_early() for a the type of trouble caused by two dominant
  144. Xcountries: Britain and France.  So, a plea to those out there that
  145. Xwant to rule the world: When you do take over, see to that the rules
  146. Xare observed consistently!  It makes everything much easier :-)
  147. X
  148. X  Some countries did not transistion directly from the Julian to the
  149. XGregorian calendar.  An alternate calendar was tried or the calendar
  150. Xwas modified only slightly.  See the france_early(), sweden_early(),
  151. Xand ussr_early() functions.
  152. X
  153. X  Some of the date/country pairs are historically naive.  By all
  154. Xrights, Israeli dates should not exist before 1948.  However because
  155. Xthe country of Palestine was following the same year rules prior to
  156. X1948, I allowed it.  Many, many such arguments can be made (e.g., how
  157. Xto handle dates in years before the USA gained independence or even
  158. Xbefore it was "discovered" by Columbus/stray Vikings/Anasazi Indians.
  159. XChange the dates to make yourself happy.
  160. X
  161. X  The list of countries is not complete.  I have no intention of 
  162. Xextending it to cover all current, past, and future countries.  If
  163. Xyou want to do it yourself, feel free to hack it up.
  164. X
  165. X  I would appreciate the reception of any changes/corrections you make!
  166. X
  167. X
  168. XBob Devine
  169. XNovember 1986 (Gregorian style numbering)
  170. X
  171. SHAR_EOF
  172. if test 5865 -ne "`wc -c < 'READ_ME'`"
  173. then
  174.     echo shar: error transmitting "'READ_ME'" '(should have been 5865 characters)'
  175. fi
  176. fi
  177. if test -f 'Makefile'
  178. then
  179.     echo shar: will not over-write existing file "'Makefile'"
  180. else
  181. echo extracting "'Makefile'"
  182. sed 's/^X//' >Makefile <<'SHAR_EOF'
  183. X# PRINTSERVER makefile
  184. X
  185. X#COPTS  = 
  186. XCOPTS  = -O
  187. X#CDEFS  = -DDEBUG 
  188. XCDEFS  =
  189. XINCDIR =
  190. XCFLAGS = $(COPTS) $(CDEFS) $(INCDIR)
  191. X
  192. XLFLAGS = 
  193. XLIBS   = 
  194. XBIN_DIR = 
  195. XPROG = year
  196. X
  197. XCFILES = \
  198. X    main.c \
  199. X    days.c \
  200. X    early.c 
  201. X
  202. X
  203. XOFILES = $(CFILES:.c=.o)
  204. XLFILES = $(CFILES:.c=.ln)
  205. X
  206. X.SUFFIXES: .ln
  207. X.c.ln:
  208. X    lint -abchu $(INCDIR) $*.c
  209. X
  210. Xbuild    : $(PROG)
  211. X
  212. Xpbuild    : $(OFILES)
  213. X    cc -p -o $(PROG) $(LFLAGS)  $(OFILES)  $(LIBS)
  214. X
  215. Xall    : $(PROG) lint
  216. X
  217. X$(PROG): $(OFILES)
  218. X    cc -o $(PROG) $(LFLAGS)  $(OFILES)  $(LIBS)
  219. X
  220. Xinstall    : $(PROG) 
  221. X    mv $(PROG) $(BIN_DIR)
  222. X
  223. Xlint    : $(LFILES)
  224. X
  225. Xclean    :
  226. X    -rm $(PROG)
  227. X    -rm *.o
  228. SHAR_EOF
  229. if test 573 -ne "`wc -c < 'Makefile'`"
  230. then
  231.     echo shar: error transmitting "'Makefile'" '(should have been 573 characters)'
  232. fi
  233. fi
  234. if test -f 'main.c'
  235. then
  236.     echo shar: will not over-write existing file "'main.c'"
  237. else
  238. echo extracting "'main.c'"
  239. sed 's/^X//' >main.c <<'SHAR_EOF'
  240. X#include <stdio.h>
  241. X
  242. X
  243. Xmain()
  244. X{
  245. X    int days_in_year();
  246. X    int year;
  247. X    int country_code;
  248. X    
  249. X    while (1)
  250. X    {
  251. X    printf("\nEnter year and country code: ");
  252. X    if (scanf("%d %d", &year, &country_code) == EOF)
  253. X        exit(0);
  254. X
  255. X    printf("it has %d days\n", days_in_year(year, country_code));
  256. X    }
  257. X}
  258. SHAR_EOF
  259. if test 295 -ne "`wc -c < 'main.c'`"
  260. then
  261.     echo shar: error transmitting "'main.c'" '(should have been 295 characters)'
  262. fi
  263. fi
  264. if test -f 'days.c'
  265. then
  266.     echo shar: will not over-write existing file "'days.c'"
  267. else
  268. echo extracting "'days.c'"
  269. sed 's/^X//' >days.c <<'SHAR_EOF'
  270. X#include <stdio.h>
  271. X
  272. Xstruct country_years
  273. X{
  274. X    short  greg_switch;        /* year according to Christian era  */
  275. X    int    (*weird_years)();    /* function pointer for early years */
  276. X};
  277. X
  278. X
  279. X#include "year.tbl"
  280. X
  281. X
  282. X
  283. X/**********************************************************************
  284. X*
  285. X*  days_in_year() -- give number of days for particular year and country
  286. X*
  287. X*     N.B. countries and their borders have changed a bit over time ...
  288. X*
  289. X*     returns:
  290. X*        -1      for unknown countries or bad years
  291. X*     # of days  for good years of countries in table
  292. X*
  293. X**********************************************************************/
  294. Xint
  295. Xdays_in_year(year, country_code)
  296. X    register int   year;
  297. X    register int   country_code;
  298. X{
  299. X    register int switch_year;
  300. X
  301. X
  302. X    /* valid country code? */
  303. X    if (country_code < 0  ||  country_code > MAX_COUNTRY)
  304. X    return(-1);
  305. X
  306. X    /* check the farthest boundaries; there is no year 0 */
  307. X    /* NOTE: individual country functions may handle less */
  308. X    if (year <= 0  ||  year > 9999)
  309. X    return(-1);
  310. X
  311. X    /* if year is after Gregorian calendar change, use Gregorian rule */
  312. X    switch_year = year_table[country_code].greg_switch;
  313. X    if (year > switch_year)
  314. X    if ((year&0x3)==0 && ((year&0xF)==0 || year%100))
  315. X        return(366);
  316. X    else
  317. X        return(365);
  318. X    
  319. X    /* else, need to handle years before and during calendar change */
  320. X    return((*year_table[country_code].weird_years)(year, switch_year));
  321. X}
  322. SHAR_EOF
  323. if test 1423 -ne "`wc -c < 'days.c'`"
  324. then
  325.     echo shar: error transmitting "'days.c'" '(should have been 1423 characters)'
  326. fi
  327. fi
  328. if test -f 'early.c'
  329. then
  330.     echo shar: will not over-write existing file "'early.c'"
  331. else
  332. echo extracting "'early.c'"
  333. sed 's/^X//' >early.c <<'SHAR_EOF'
  334. X#include <stdio.h>
  335. X
  336. X
  337. X/**********************************************************************
  338. X*
  339. X* unknown_calendar() -- ignorance place holder
  340. X*
  341. X*     This is for countries that I don't know about.  It is used for
  342. X*   the Muslim, Celtic, Chinese, Mayan, and other calendars.
  343. X*
  344. X**********************************************************************/
  345. Xint unknown_calendar(year, change_year)
  346. X    int year;
  347. X    int change_year;
  348. X{
  349. X    return(-1);
  350. X}
  351. X
  352. X
  353. X/**********************************************************************
  354. X*
  355. X* julian() -- return length of year based on Julius Caesar/Sosigenes rule
  356. X*
  357. X*     Actually could go back to 45 BC, but why?
  358. X*     Calling routine allows no years before 1 AD 
  359. X*
  360. X**********************************************************************/
  361. Xint julian(year, change_year)
  362. X    int year;
  363. X    int change_year;
  364. X{
  365. X    int length = 365;
  366. X
  367. X
  368. X    if ((year & 03) == 0)
  369. X    length = 366;
  370. X
  371. X    if (year == change_year)
  372. X    switch (change_year / 100)
  373. X    {
  374. X    case 20:
  375. X        /* 2000 - 2099 */
  376. X        /* 2000 is a leap year; fall through */
  377. X    case 19:
  378. X        /* 1900 - 1999 */
  379. X        return(length-13);
  380. X    case 18:
  381. X        /* 1800 - 1899 */
  382. X        return(length-12);
  383. X    case 17:
  384. X        /* 1700 - 1799 */
  385. X        return(length-11);
  386. X    case 16:
  387. X        /* 1600 - 1699 */
  388. X        /* 1600 is a leap year, fall through */
  389. X    case 15:
  390. X        /* 1500 - 1599 */
  391. X        return(length-10);
  392. X    }
  393. X
  394. X    return(length);
  395. X}
  396. X
  397. X
  398. X/**********************************************************************
  399. X*
  400. X* belgium_early() -- handle problem caused by the change to Gregorian
  401. X*                    overlapping two years
  402. X*
  403. X**********************************************************************/
  404. Xint belgium_early(year, change_year)
  405. X    int year;
  406. X    int change_year;
  407. X{
  408. X    /* the days 12/25/1582 - 1/5/1583 were dropped */
  409. X    if (year == change_year || year == change_year-1)
  410. X        return(360);
  411. X
  412. X    /* do normal Julian rules */
  413. X    if ((year & 03) == 0)
  414. X    return(366);
  415. X    else
  416. X    return(365);
  417. X}
  418. X
  419. X
  420. X/**********************************************************************
  421. X*
  422. X*  canada_early() -- deal with conflict between French rules and
  423. X*                    British rules for dates
  424. X*
  425. X*   France changed to Gregorian 12/10/1582 (Julian)
  426. X*   Britain changed to Gregorian 09/05/1752 (Julian)
  427. X*   therefore, Canada changed on ??/??/????
  428. X*
  429. X*   Some guesses can be made based on the individual provinces/territories:
  430. X*
  431. X*     Alberta                  British rules likely apply
  432. X*     British Columbia         British rules definitely apply
  433. X*     Manitoba                 likely British rules (def. British after 1763)
  434. X*     New Brunswick            France and British alternated control
  435. X*     Newfoundland             contested until 1713 when became British
  436. X*     Nova Scotia              British after 1713
  437. X*     Ontario                  French first then British after 1759
  438. X*     Prince Edward Island     follows Ontario rules (?)
  439. X*     Quebec                   Britain gained in 1763 with Treaty of Paris
  440. X*     Saskatchewan             British rules apply
  441. X*     Yukon Territory          first Russian then British after 1840 (?)
  442. X*
  443. X**********************************************************************/
  444. Xint canada_early(year, change_year)
  445. X    int year;
  446. X    int change_year;
  447. X{
  448. X    /* calculate using British change year for Canada's */
  449. X    return(julian(year, change_year));
  450. X}
  451. X
  452. X
  453. X/**********************************************************************
  454. X*
  455. X* china_early() -- previous to using the Gregorian calendar, China
  456. X*                  used a 12 (ordinary year) or 13 (full year) month
  457. X*                  calendar that operated in 60 year cycles
  458. X*                  Years began with the lunar month that had the sun
  459. X*                  enter the zodiacal sign Aquarius
  460. X*
  461. X*                  Jesuit missionaries tried to reform the calendar
  462. X*                  when they arrived in the 1600s.  I haven't found
  463. X*                  out the full ramifications of that attempt.  What I
  464. X*                  have seen is that the calendar was again changed by
  465. X*                  the Chinese after that; this introduced some errors.
  466. X*
  467. X*                  Now, what that means for converting years is
  468. X*                  a lot of work...
  469. X*
  470. X**********************************************************************/
  471. Xint china_early(year, change_year)
  472. X    int year;
  473. X    int change_year;
  474. X{
  475. X    /* punt */
  476. X    return(-1);
  477. X}
  478. X
  479. X
  480. X
  481. X/**********************************************************************
  482. X*
  483. X* france_early() -- deal with France's use of the Republic calendar
  484. X*                   for the years 1793-1805
  485. X*
  486. X*    The Revolutionary Calendar was a base 10 calendar.  That is, it
  487. X*  had 360 days arranged in 12 months of 30 days plus 5 or 6 unnumbered
  488. X*  days that were added to the end of the last month.  Each day was 10
  489. X*  hours of 100 minutes of 100 seconds long.
  490. X*
  491. X*    It was rejected after over a decade of use mainly because of its
  492. X*  opposition from religious groups who did not approve of weeks that
  493. X*  were seven days long.
  494. X*
  495. X**********************************************************************/
  496. Xint france_early(year, change_year)
  497. X    int year;
  498. X    int change_year;
  499. X{
  500. X    /* Republic --> Gregorian */
  501. X    if (year == 1806)
  502. X    return(365);    /* ? */
  503. X
  504. X    /* Republic Calendar -- follows Julian leap-year rule */
  505. X    if (year > 1793  ||  year < 1806)
  506. X    {
  507. X    if ((year & 03) == 0)
  508. X        return(366);
  509. X    else
  510. X        return(365);
  511. X    }
  512. X
  513. X    /* Gregorian --> Republic */
  514. X    if (year == 1793)
  515. X    return(365);
  516. X
  517. X    /* Gregorian */
  518. X    if (year > 1582  ||  year < 1793)
  519. X    {
  520. X    if ((year&0x3)==0 && ((year&0xF)==0 || year%100))
  521. X       return(366);
  522. X    else
  523. X       return(365);
  524. X    }
  525. X
  526. X    /* Julian --> Gregorian */
  527. X    if (year == 1582)
  528. X    return(365-10);        /* dropped the days 12/10 - 12/20 */
  529. X
  530. X    /* Julian */
  531. X    if ((year & 03) == 0)
  532. X    return(366);
  533. X    else
  534. X    return(365);
  535. X}
  536. X
  537. X
  538. X/**********************************************************************
  539. X*
  540. X* german_early() -- deal with problem of country adopting the
  541. X*                   Gregorian calendar in parts
  542. X*
  543. X*  Gregorian calendar was adopted in overlapping parts:
  544. X*      10/16/1583   Bavaria
  545. X*      11/14/1583   the Catholic population
  546. X*       3/01/1682   Strassburg
  547. X*      11/15/1699   the Protestant population
  548. X*      12/12/1700   Utrecht
  549. X*
  550. X*  I have the last date (1700) in the table for the entire country.
  551. X*  If you want more accuracy in dealing with the partial changes,
  552. X*  make modifications to the country table and the following code.
  553. X*
  554. X**********************************************************************/
  555. Xint german_early(year, change_year)
  556. X    int year;
  557. X    int change_year;
  558. X{
  559. X    /* deal with change-over date */
  560. X    if (year == change_year)
  561. X    return(366-11);            /* 1700 is a leap year */
  562. X
  563. X    /* else, do normal Julian rules */
  564. X    if ((year & 03) == 0)
  565. X    return(366);
  566. X    else
  567. X    return(365);
  568. X}
  569. X
  570. X
  571. X
  572. X/**********************************************************************
  573. X*
  574. X* greece_early() -- country did not change all at one time
  575. X*
  576. X*    The changes that occurred are:
  577. X*
  578. X*        07/15/1916  Calendar change adopted by all except...
  579. X*        09/30/1923  ...the Greek Church, which finally accepted it
  580. X*
  581. X*    The table uses the latter date.  Hack this if you don't like it.
  582. X*    A warning:  one reference seemed to indicated (it wasn't clear if
  583. X*    it had been just proposed or it was accepted) that Greece is using a
  584. X*    modified Julian calendar that has two leap centuries out of *nine*.
  585. X*    If this is true, then dates after 2800 will be different from
  586. X*    the Gregorian calendar.
  587. X*
  588. X**********************************************************************/
  589. Xint greece_early(year, change_year)
  590. X    int year;
  591. X    int change_year;
  592. X{
  593. X    /* do change-over year */
  594. X    if (year == change_year)
  595. X    return(365-13);        /* 1923 was not a leap year */
  596. X
  597. X    /* do normal Julian rules */
  598. X    if ((year & 03) == 0)
  599. X    return(366);
  600. X    else
  601. X    return(365);
  602. X}
  603. X
  604. X
  605. X/**********************************************************************
  606. X*
  607. X* iran_early() -- uses the Monarchic Calendar
  608. X*
  609. X*  I don't know how if or when Gregorian was used.  The Muslim
  610. X*  calendar may still be used (it is a 12 month calendar with a 30
  611. X*  year cycle;  eleven days are added over the cycle) for daily or
  612. X*  religious or even Government functions.
  613. X*
  614. X**********************************************************************/
  615. Xint iran_early(year, change_year)
  616. X    int year;
  617. X    int change_year;
  618. X{
  619. X    return(-1);
  620. X}
  621. X
  622. X
  623. X/**********************************************************************
  624. X*
  625. X* japan_early() -- deal with Japanese lunar calendar
  626. X*
  627. X*   Unfortunately, I have been unable to find any detailed information
  628. X*   on the calendar used prior to the adoption of the Gregorian calendar.
  629. X*
  630. X*   If anyone has some info, I'd like to receive it.
  631. X*
  632. X**********************************************************************/
  633. Xint japan_early(year, change_year)
  634. X    int year;
  635. X    int change_year;
  636. X{
  637. X    return(-1);
  638. X}
  639. X
  640. X
  641. X/**********************************************************************
  642. X*
  643. X* netherlands_early() -- deal with scattered adoption
  644. X*
  645. X*  Adoption of the Gregorian calendar went by the following cities:
  646. X*     12/15/1582   Holland, Zeeland, Brabant, Vlaandern
  647. X*     06/30/1700   Gelerland
  648. X*     11/30/1700   Utrecht, Overijisol
  649. X*     12/31/1700   Friesland, Groningen
  650. X*     01/12/1701   Entire country consistent
  651. X*
  652. X**********************************************************************/
  653. Xint netherlands_early(year, change_year)
  654. X    int year;
  655. X    int change_year;
  656. X{
  657. X    /* Use date of total country adoption -- 1701 */
  658. X    if (year == change_year)
  659. X    return(365 - 11);
  660. X
  661. X    /* do normal Julian rules */
  662. X    if ((year & 03) == 0)
  663. X    return(366);
  664. X    else
  665. X    return(365);
  666. X}
  667. X
  668. X
  669. X/**********************************************************************
  670. X*
  671. X* poland_early() -- deal with country's partial adoption dates
  672. X*
  673. X*  Dates for adoption are
  674. X*      11/01/1582   Catholics (and Protestants?) adopt
  675. X*      03/18/1918   Russian Poland changes (Civil War split)
  676. X*      05/??/1923   Orthodox members adopt
  677. X*
  678. X**********************************************************************/
  679. Xint poland_early(year, change_year)
  680. X    int year;
  681. X    int change_year;
  682. X{
  683. X    /* Use date of total country adoption -- 1923 */
  684. X    if (year == change_year)
  685. X    return(365 - 13);
  686. X
  687. X    /* do normal Julian rules */
  688. X    if ((year & 03) == 0)
  689. X    return(366);
  690. X    else
  691. X    return(365);
  692. X}
  693. X
  694. X
  695. X/**********************************************************************
  696. X*
  697. X* sweden_early() -- deal with bouncing leap day
  698. X*
  699. X*  Sweden took a half-step towards Gregorian but then retreated (think
  700. X*  of it as sort of a single partner polka).
  701. X*
  702. X*       1700 -- made this year a non-leap year by dropping Feb 29th
  703. X*       1712 -- went back to Julian calendar by making a Feb 30th !!
  704. X*  2/18/1753 -- adopted Gregorian
  705. X*
  706. X**********************************************************************/
  707. Xint sweden_early(year, change_year)
  708. X    int year;
  709. X    int change_year;
  710. X{
  711. X    if (year == change_year)
  712. X    return(365 - 11);
  713. X
  714. X    if (year == 1700)
  715. X    return(365);
  716. X
  717. X    if (year == 1712)
  718. X    return(367);
  719. X
  720. X    /* do normal Julian rules */
  721. X    if ((year & 03) == 0)
  722. X    return(366);
  723. X    else
  724. X    return(365);
  725. X}
  726. X
  727. X
  728. X/**********************************************************************
  729. X*
  730. X* switzerland_early() -- deal with scattered adoption in country
  731. X*
  732. X*  Districts and their adoption dates (I had conflicting sources for
  733. X*  the spelling of the district names)
  734. X*
  735. X*  Catholic districts 
  736. X*     01/22/1584  Fribourg, Lucerne, Schwyz, Solothurn, Unterwalden, Uri, Zug
  737. X*     01/17/1597  Appenzell
  738. X*     03/01/1656  Valais (part did early in 1622)
  739. X*
  740. X*  Protestant districts 
  741. X*     01/01/1701  Baselstradt, Bern, Biel, Cargous, Geneva, Neuchatel,
  742. X*                 Schaffhausen, Thurgan, and Zurich
  743. X*     12/20/1723  Appenzell
  744. X*     01/12/1724  Glarus, St. Galen
  745. X*     02/17/1812  Grisons
  746. X*
  747. X**********************************************************************/
  748. Xint switzerland_early(year, change_year)
  749. X    int year;
  750. X    int change_year;
  751. X{
  752. X    /* Use date of total country adoption -- 1724 (a leap year) */
  753. X    if (year == change_year)
  754. X    return(366 - 11);
  755. X
  756. X    /* do normal Julian rules */
  757. X    if ((year & 03) == 0)
  758. X    return(366);
  759. X    else
  760. X    return(365);
  761. X}
  762. X
  763. X
  764. X/**********************************************************************
  765. X*
  766. X* turkey_early() -- deal with scattered adoption of new calendar
  767. X*
  768. X*  Adoption seemed to depend on regional background
  769. X*
  770. X*      1908  people with a European heritage
  771. X*      1917  people with a Asian heritage (might be 1914)
  772. X*
  773. X**********************************************************************/
  774. Xint turkey_early(year, change_year)
  775. X    int year;
  776. X    int change_year;
  777. X{
  778. X    /* Use date of total country adoption -- 1917 */
  779. X    if (year == change_year)
  780. X    return(365 - 13);
  781. X
  782. X    /* do normal Julian rules */
  783. X    if ((year & 03) == 0)
  784. X    return(366);
  785. X    else
  786. X    return(365);
  787. X}
  788. X
  789. X
  790. X/**********************************************************************
  791. X*
  792. X* usa_early() -- deal with state differences
  793. X*
  794. X*  The USA, for the most part, followed Great Britain's lead in the
  795. X*  adoption of the the Gregorian calendar in 1752.  However, not all
  796. X*  current states were part of the "country" at that time.  An easy
  797. X*  lie is to say that all parts of the yet-to-be USA changed over on
  798. X*  that date.  States like California were not even settled until
  799. X*  about 1770.
  800. X*
  801. X*  The exceptions to the 1752 rule:
  802. X*
  803. X*  Alaska was owned by Russia until 1867. (see Russia's rules)
  804. X*  Hawaii was an independent country that adopted Gregorian in 1893(?).
  805. X*
  806. X*  The non-states that operate under US protection are likewise exceptions
  807. X*  to the rule (luckily, some were not inhabited or we'd have to hypnotise
  808. X*  the native population to change their memory of previous calendars:-):
  809. X*
  810. X*  American Samoa became possesion 1899.
  811. X*  Baker, Howland, and Jarvis Islands became possesions 1857(?).
  812. X*  Panama Canal Zone was a possesion 1903-1979 (?).
  813. X*  Canton and Enderbury Islands - 1939.
  814. X*  Great Corn and Little Corn - leased from Nicaraugua for 99 years in 1914.
  815. X*  Guam - obtained in 1898, lost to Japan 1941, regained in 1944.
  816. X*  Johnston Island - came with Hawaii
  817. X*  Midway Islands - 1867
  818. X*  Phillipine Islands - was US territory 1898-1946
  819. X*  Puerto Rico - Spain ceded to US in 1898
  820. X*  Trust Territories of the Pacific (approx 2000 islands in W. Pacific)-1947
  821. X*  Virgin Islands - bought from Denmark in 1917
  822. X*  Wake Island - got from Spain 1898, Japan took 1941, regained in 1945
  823. X*
  824. X**********************************************************************/
  825. Xint usa_early(year, change_year)
  826. X    int year;
  827. X    int change_year;
  828. X{
  829. X    /* this is for the majority of the cases,  change if desired */
  830. X    if (year == change_year)    /* 1752 */
  831. X    return(366 - 11);
  832. X
  833. X    /* do normal Julian rules */
  834. X    if ((year & 03) == 0)
  835. X    return(366);
  836. X    else
  837. X    return(365);
  838. X}
  839. X
  840. X
  841. X/**********************************************************************
  842. X*
  843. X* ussr_early() -- deal with scattered adoption of new calendar
  844. X*
  845. X* The changing calendar for the Soviet Union reflects a country
  846. X* that was undergoing great changes.  The dates of change are:
  847. X*
  848. X*   1/1/1918 -- Western part changes to Gregorian
  849. X*   2/5/1920 -- Eastern part changes to Gregorian
  850. X*       1929 -- Entire country changed to a 5 day week and new calendar
  851. X*       1932 -- Entire country changed to a 6 day week and new calendar
  852. X*  6/27/1940 -- Chucked the non-standard calendar and returned to Gregorian
  853. X*
  854. X**********************************************************************/
  855. Xint ussr_early(year, change_year)
  856. X    int year;
  857. X    int change_year;
  858. X{
  859. X    /* the above is the present and total knowledge I have on the */
  860. X    /* calendars used....  So, I'll punt and return(-1);          */
  861. X    return(-1);
  862. X}
  863. SHAR_EOF
  864. if test 15537 -ne "`wc -c < 'early.c'`"
  865. then
  866.     echo shar: error transmitting "'early.c'" '(should have been 15537 characters)'
  867. fi
  868. fi
  869. if test -f 'year.tbl'
  870. then
  871.     echo shar: will not over-write existing file "'year.tbl'"
  872. else
  873. echo extracting "'year.tbl'"
  874. sed 's/^X//' >year.tbl <<'SHAR_EOF'
  875. X#define VATICAN_CITY    00
  876. X#define UNITED_STATES   01
  877. X#define CANADA          02
  878. X#define MEXICO          03
  879. X#define AUSTRALIA       04
  880. X#define AUSTRIA         05
  881. X#define BELGIUM         06
  882. X#define BRAZIL          07
  883. X#define CHILE           08
  884. X#define CHINA           09
  885. X#define CZECHOSLOVAKIA  10
  886. X#define DENMARK         11
  887. X#define EGYPT           12
  888. X#define FINLAND         13
  889. X#define FRANCE          14
  890. X#define GERMANY         15
  891. X#define GREAT_BRITAIN   16
  892. X#define GREECE          17
  893. X#define HONG_KONG       18
  894. X#define HUNGARY         19
  895. X#define INDIA           20
  896. X#define IRAN            21
  897. X#define IRAQ            22
  898. X#define ISRAEL          23
  899. X#define IRELAND         24
  900. X#define ITALY           25
  901. X#define JAPAN           26
  902. X#define SOUTH_KOREA     27
  903. X#define NETHERLANDS     28
  904. X#define NEW_ZEALAND     29
  905. X#define NORWAY          30
  906. X#define POLAND          31
  907. X#define SAUDI_ARABIA    32
  908. X#define SCOTLAND        33
  909. X#define SINGAPORE       34
  910. X#define SOUTH_AFRICA    35
  911. X#define SOVIET_UNION    36
  912. X#define SPAIN           37
  913. X#define SWEDEN          38
  914. X#define SWITZERLAND     39
  915. X#define TAIWAN          40
  916. X#define THAILAND        41
  917. X#define TURKEY          42
  918. X
  919. X#define MAX_COUNTRY     43
  920. X
  921. X
  922. Xextern int unknown_calendar();
  923. Xextern int julian();
  924. X
  925. Xextern int belgium_early();
  926. Xextern int usa_early();
  927. Xextern int canada_early();
  928. Xextern int china_early();
  929. Xextern int france_early();
  930. Xextern int german_early();
  931. Xextern int greece_early();
  932. Xextern int iran_early();
  933. Xextern int japan_early();
  934. Xextern int netherlands_early();
  935. Xextern int poland_early();
  936. Xextern int ussr_early();
  937. Xextern int sweden_early();
  938. Xextern int switzerland_early();
  939. Xextern int turkey_early();
  940. X
  941. X
  942. X
  943. Xstruct  country_years  year_table[MAX_COUNTRY] =
  944. X{
  945. X    { /* VATICAN_CITY    */  1582, julian},
  946. X    { /* UNITED_STATES    */  1752, usa_early},
  947. X    { /* CANADA        */  1806, canada_early},
  948. X    { /* MEXICO        */  1582, julian},
  949. X    { /* AUSTRALIA    */  1582, julian},
  950. X    { /* AUSTRIA    */  1583, julian},
  951. X    { /* BELGIUM    */  1583, belgium_early},
  952. X    { /* BRAZIL        */  1582, julian},
  953. X    { /* CHILE        */  1582, julian},
  954. X    { /* CHINA        */  1912, china_early},
  955. X    { /* CZECHOSLOVAKIA    */  1891, unknown_calendar},
  956. X    { /* DENMARK    */  1582, julian},        /* 1700 ? */
  957. X    { /* EGYPT        */  1900, unknown_calendar},
  958. X    { /* FINLAND    */  1918, julian},
  959. X    { /* FRANCE        */  1806, france_early},
  960. X    { /* GERMANY    */  1700, german_early},
  961. X    { /* GREAT_BRITAIN    */  1752, julian},
  962. X    { /* GREECE        */  1924, greece_early},    /* 1920? */
  963. X    { /* HONG_KONG    */  1752, julian},
  964. X    { /* HUNGARY    */  1587, julian},        /* 1582? */
  965. X    { /* INDIA        */  1752, unknown_calendar},
  966. X    { /* IRAN        */  9999, iran_early},
  967. X    { /* IRAQ        */  1918, unknown_calendar},
  968. X    { /* ISRAEL        */  1752, julian},
  969. X    { /* IRELAND    */  1752, julian},
  970. X    { /* ITALY        */  1582, julian},    /* Mar 25 = new year for parts*/
  971. X    { /* JAPAN        */  1873, japan_early},        /* 1893? */
  972. X    { /* SOUTH_KOREA    */  1873, japan_early},        /* 1893? */
  973. X    { /* NETHERLANDS    */  1702, netherlands_early},
  974. X    { /* NEW_ZEALAND    */  1752, julian},
  975. X    { /* NORWAY        */  1700, unknown_calendar},    /* prob. Celtic cal */
  976. X    { /* POLAND        */  1923, poland_early},
  977. X    { /* SAUDI_ARABIA    */  1900, unknown_calendar},
  978. X    { /* SCOTLAND        */  1752, julian},
  979. X    { /* SINGAPORE    */  1752, julian},
  980. X    { /* SOUTH_AFRICA    */  1752, julian},
  981. X    { /* SOVIET_UNION    */  1940, ussr_early},
  982. X    { /* SPAIN        */  1582, julian},
  983. X    { /* SWEDEN        */  1753, sweden_early},
  984. X    { /* SWITZERLAND    */  1724, switzerland_early},
  985. X    { /* TAIWAN        */  1873, japan_early},
  986. X    { /* THAILAND    */  1920, unknown_calendar},
  987. X    { /* TURKEY        */  1917, turkey_early}        /* 1914? */
  988. X};
  989. SHAR_EOF
  990. if test 3617 -ne "`wc -c < 'year.tbl'`"
  991. then
  992.     echo shar: error transmitting "'year.tbl'" '(should have been 3617 characters)'
  993. fi
  994. fi
  995. # end of shell archive
  996. exit 0
  997.  
  998.  
  999.